package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyJtfz;
import cn.stylefeng.guns.sys.modular.system.mapper.BtyJtfzMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyJtfzParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyJtfzResult;
import  cn.stylefeng.guns.sys.modular.system.service.BtyJtfzService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuy
 * @since 2022-02-25
 */
@Service
public class BtyJtfzServiceImpl extends ServiceImpl<BtyJtfzMapper, BtyJtfz> implements BtyJtfzService {

    @Override
    public void add(BtyJtfzParam param){
        BtyJtfz entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BtyJtfzParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BtyJtfzParam param){
        BtyJtfz oldEntity = getOldEntity(param);
        BtyJtfz newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BtyJtfzResult findBySpec(BtyJtfzParam param){
        return null;
    }

    @Override
    public List<BtyJtfzResult> findListBySpec(BtyJtfzParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BtyJtfzParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public boolean insertJtFz(List<BtyJtfz> list) {
        return baseMapper.insertJtfz(list);
    }

    @Override
    public List<BtyJtfzResult> customList(BtyJtfzParam param) {
        return baseMapper.customList(param);
    }

    @Override
    public List<BtyJtfzResult> jtfzList() {
        return baseMapper.jtfzList();
    }

    private Serializable getKey(BtyJtfzParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BtyJtfz getOldEntity(BtyJtfzParam param) {
        return this.getById(getKey(param));
    }

    private BtyJtfz getEntity(BtyJtfzParam param) {
        BtyJtfz entity = new BtyJtfz();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
